package LeetCode;

import javax.swing.plaf.synth.SynthTabbedPaneUI;
import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.List;
import java.util.Stack;

/**
 * @author VX5
 * @Title: MJC
 * @ProjectName DataStructure
 * @Description: TODO
 * @date ${DAT}17:59
 */
public class E5 {//将链表倒着打出来

    public static void main(String[] args) {
        ListNode head = new ListNode(1);
        head.next = new ListNode(3);
        head.next.next = new ListNode(2);
        System.out.println(Arrays.toString(reversePrint(head)));
    }

    public static int[] reversePrint(ListNode head){
        Stack<Integer> stack = new Stack();
        int i =0;

        while (true){
            if (head!=null){
                stack.add(head.val);
                i++;
            }else {
                break;
            }
            head = head.next;
        }
        int[] result = new int[i];
        for (int j = 0; j < i;j++){
            result[j] = stack.pop();
        }
        return result;
    }

    static class ListNode {
      int val;
      ListNode next;
      public ListNode(int x) {
          val = x;
      }
    }
}
